import request from '@/utils/request'
import { method } from 'lodash';

export function getIpSegmentList(query) {
    return request({
        url: `/system/ip/pool/${query}`,
        method: 'get',
    })
}

export function delIpSegment(id) {
  return request({
    url: `/system/ip/segment/${id}`,
    method: "delete",
    timeout: 1000 * 60 * 5,
  });
}

// 查询IP池管理列表
export function listPool(data) {
  return request({
    url: '/system/ip/pool/list',
    method: 'get',
    params: data
  })
}

// 查询IP池管理列表
export function listPoolByOrgName(data) {
  return request({
    url: '/system/ip/pool/listByOrgName',
    method: 'post',
    data: data
  })
}

export function getAllOrgList(query) {
  return request({
    url: 'system/ip/pool/selectOtgTree',
    method: 'get',
    params: query
  })
}

export function getAllPoolList(query) {
  return request({
    url: 'system/ip/pool/selectTree',
    method: 'get',
    params: query
  })
}


// 查询IP池管理详细
export function getPool(id) {
  return request({
    url: '/system/ip/pool/' + id,
    method: 'get'
  })
}

// 新增IP池管理
export function addPool(data) {
  return request({
    url: '/system/ip/pool',
    method: 'post',
    data: data
  })
}

// 新增IP段配置
export function handleAddIpSegment(data) {
    return request({
        url: '/system/ip/segment',
        method: 'post',
        timeout: 1000 * 60 * 5,
        data: data
    })
}

// 修改IP池管理
export function updatePool(data) {
  return request({
    url: '/system/ip/pool',
    method: 'put',
    data: data
  })
}

export function splitIpSegment(data) {
    return request({
        url: '/system/ip/segment/splitSegment',
        method: 'put',
        data: data
    })
}

export function mergeIpSegment(data) {
    return request({
        url: '/system/ip/segment/mergeSegment',
        method: 'put',
        data: data
    })
}

// 删除IP池管理
export function delPool(id) {
  return request({
    url: '/system/ip/pool/' + id,
    method: 'delete'
  })
}

// 在IP池中预占一定数量的IP
export function assignIP(poolId, ipSum) {
  return request({
    url: '/system/ip/resource/ipAllot?poolId=' + poolId + "&ipSum=" + ipSum,
    method: 'get'
  })
}

// 在IP池中占用一定数量的IP
export function occupyIP(ipAddressField) {
  return request({
    url: '/system/ip/resource/ipOccupy?ipAddressField=' + encodeURI(ipAddressField),
    method: 'get'
  })
}


// 新增
export function addIpSegments(data) {
    return request({
        url: '/system/ip/segment/addSon',
        method: 'post',
        data: data
    })
}


// ip 池搜索
export function searchPool(data) {
  return request({
    url: '/system/ip/pool/selectStaticIp',
    method: 'post',
    data: data
  })
}

// 懒加载
export function lzaylist(id) {
  return request ({
    url: '/system/ip/pool/selectJunior/' + id,
    method:"get"
  })
}

// 懒加载获取子级
export function getChildList(parentId) {
  return request({
    url: '/system/ip/pool/selectJunior/'+parentId,
    method: 'get'
    })
}


// 查询合并IP段列表
export function listMergeSegment(data) {
  return request({
    url: '/system/ip/segment/ipAddressFieldS',
    method: 'get',
    params: data
  })
}

// 查询使用机构
export function listOrg() {
  return request({
    url: '/system/ip/pool/authData',
    method: 'get',
  })
}

// 查询使用机构
export function listOrgByParentId(parentId) {
  return request({
    url: '/system/ip/pool/authData?parentId=' + parentId,
    method: 'get',
  })
}

// 使用机构数据联动
export function listOrgData(data) {
  return request({
    url: '/system/ip/pool/selectIpOrg',
    method: 'get',
    params: data
  })
}

// 获取APN
export function getListApn() {
  return request({
    url: '/system/ip/pool/getListApn',
    method: 'get'
  })
}


// 获取应用场景
export function gitapply_scene() {
  return request({
    url: '/system/dict/data/type/apply_scene',
    method: 'get'
  })
}

// 获取父级应用场景
export function getfatherIpool(id){
  return request({
    url: '/system/ip/pool/getApplySceneListByParentPoolId',
    method: 'get',
    params: id
  })
}